﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentExceptions
{
    class StudentTest
    {
        static void Main()
        {
            while (true)
            {
                try
                {
                    Student student = new Student();
                    Console.Write("Age: ");
                    int age = 0;
                    int.TryParse(Console.ReadLine(), out age);
                    if (age != 0)
                    {
                        student.Age = age;
                    }
                    else
                    {
                        throw new InvalidStudentException("This is not a valid age. Must be between 7 and 18.");
                    }

                    Console.Write("Gender: ");
                    string genderRead = Console.ReadLine();
                    Gender gender;
                    switch (genderRead)
                    {
                        case "Male":
                            gender = Gender.Male;
                            break;
                        case "Female":
                            gender = Gender.Female;
                            break;
                        default:
                            gender = Gender.undefined;
                            break;
                    }
                    student.Gender = gender;

                    Console.Write("Name: ");
                    string name = Console.ReadLine();
                    student.Name = name;

                    Console.Write("Class: ");
                    student.Clas = byte.Parse(Console.ReadLine());
                }
                catch (InvalidStudentException ise)
                {
                    Console.WriteLine(ise.Message);
                }
            }
        }
    }
}
